<?php
    require_once './handler/check_session.php';
    require_once './data/Banque.php';
    
    $banque = unserialize($_SESSION['banque']);
    list($adresse1, $adresse2, $adresse3, $adresse4) = explode(ConfigClement::$separator_address, $banque->adress);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
        <title>Inscription</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <link rel="STYLESHEET" type="text/css" href="style/header_footer_style.css" />
        <link rel="STYLESHEET" type="text/css" href="style/main_style.css" />
        <link rel="STYLESHEET" type="text/css" href="style/pwdwidget.css" />
        <script type="text/javascript" src="scripts/pwdwidget.js"></script>      
    </head>
    <body>
        <!-- HEADER -->
        <?php include_once './include/header.php'; ?>
        <!-- MAIN -->
        <div id="main" class='myinfo'>
            <!-- CONTENT -->  
            <form id='modify' action='./handler/modify_info_treatment.php' method='post' accept-charset='UTF-8'>
                <?PHP if(isset($_GET["myinfo_error"])){ ?>
					<div class='notify'><span>&nbsp;Modification &eacute;chou&eacute;e, veuillez v&eacute;rifier que vous avez saisi le bon mot de passe</span></div>
				<?PHP } else { ?>
					<div class='notify'></div>
				<?PHP } ?>
                <fieldset class='fieldset_section'>
                    <legend>Mon compte</legend>
                    <table>
                        <tr>
                            <td class='label'><label for='name' >Nom*</label></td>
                            <td class='input'><input type='text' name='name' id='name' value='<?php echo $banque->nom ?>' maxlength="50" /></td>
                        </tr>
                         <tr>
							<td class='label'><label for='adresse1' >Adresse / Rue*</label></td>
							<td class='input'><input type='text' name='adresse1' id='adresse1' value='<?php echo $adresse1; ?>' maxlength="50" /></td>
                        </tr>
                        <tr>
							<td class='label'><label for='adresse2' >Adresse / Compl&eacute;ment</label></td>
							<td class='input'><input type='text' name='adresse2' id='adresse2' value='<?php echo $adresse2; ?>' maxlength="50" /></td>
                        </tr>
                        <tr>
                            <td class='label'><label for='adresse3&4' >CP - Ville*</label></td>
							<td class='input'><input type='text' class='cp' name='adresse3' id='adresse3' value='<?php echo $adresse3; ?>' maxlength="5" />&nbsp;<input type='text' class='ville' name='adresse4' id='adresse4' value='<?php echo $adresse4; ?>' maxlength="30" /></td>
                        </tr>
                        <tr>
                            <td class='label'><label for='phone' >N&deg; téléphone*</label></td>
                            <td class='input'><input type='text' name='phone' id='phone' value='<?php echo $banque->phone ?>' maxlength="50" /></td>
                        </tr>
                        <tr>
                            <td class='label'><label for='email' >Email*</label></td>
                            <td class='input'><input type='text' name='email' id='email' value='<?php echo $banque->mail ?>' maxlength="50" /></td>
                        </tr>
                        <tr>
                            <td class='label'><label for='passworda' >Mot de passe actuel*</label></td>
                            <td class='input'><input type='password' onkeyup="javascript:checkmdp()" name='mdp' id='mdp' maxlength="50" />  </td>                      
                        </tr>
               			 <tr>
                            <td class='label'><label for='passwordb' >Nouveau mot de passe*</label></td>
                            <td class='input'><input type='password' disabled='disabled' name='new_mdp' id='new_mdp' maxlength="50" /></td>                           
                        </tr>
                         <tr>
                            <td class='label'><label for='passwordc' >Vérifier mot de passe*</label></td>
                            <td class='input'><input type='password' disabled='disabled' name='check_new_mdp' id='check_new_mdp' maxlength="50" /></td>
                        </tr>
                    </table>
                    <div class='message'>* champs obligatoires</div>
                </fieldset>
				<div><br/>
					<input type="button" onclick="javascript:checkFields()" name="Submit" value="Enregister" />
				</div>
            </form>

        </div>
        <!-- FOOTER -->
        <?php include_once './include/footer.php'; ?>
    </body>
</html>

<script>
	function checkmdp()
	{
		if(document.getElementById("mdp").value != "")
		{
			document.getElementById("new_mdp").disabled = false;
			document.getElementById("check_new_mdp").disabled = false;
		}else{
	
			document.getElementById("new_mdp").disabled = true;
			document.getElementById("check_new_mdp").disabled = true;
		}
	}
	
	function checkFields()
	{
	
	var isgood = checkFieldsEmpty();
	
	if(!isgood)
		return;
	
	 var isgood = checkFieldsMdpEquals();
	
	 if(!isgood)
		 return;
	
	 	document.forms["modify"].submit();
	 		
		
	}
	
	function checkFieldsEmpty()
	{
		var listValue = ["name", "adresse1", "adresse3", "adresse4", "phone", "email"];
		var good = true;
		
		for(var i= 0; i < listValue.length; i++)
		{
			var val = listValue[i];
			var fieldValue = document.getElementById(val);
	
			if(fieldValue.value == null || fieldValue.value == "")
			{
				fieldValue.style.border = 'red 2px solid';
				fieldValue.style.backgroundColor = '#FDF1B8';
				if(good)
					good = false;
			}else{
				fieldValue.style.border = '';
				fieldValue.style.backgroundColor = '';
			}
	
		}
	
	
		if(!good)
		{
			alert("Certains éléments obligatoires sont manquants");
		}
	
		return good;
	
	}
	
	
	function checkFieldsMdpEquals()
	{
		
		var pwd = document.getElementById("mdp").value;
		var new_pwd = document.getElementById("new_mdp").value;
		var new_pwd2 = document.getElementById("check_new_mdp").value;
	
	
		if(pwd != null && pwd != "")
		{
			if(new_pwd != new_pwd2)
			{
				alert("Les 2 mots de passe ne correspondent pas");
				return false;
			}
		}
	
		return true;
	
	}
</script>